﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace MyHomeLib.Utils
{
  public static class Queued
  {
    public static Task Run(Action action)
    {
      return Task.Factory.StartNew(action,
                                   CancellationToken.None, 
                                   TaskCreationOptions.None, 
                                   OrderedTaskScheduler.Instance);
    }
    public static Task<T> Run<T>(Func<T> action)
    {
      return Task.Factory.StartNew(action,
                                   CancellationToken.None,
                                   TaskCreationOptions.None,
                                   OrderedTaskScheduler.Instance);
    }
    public static Task<List<T>> RunQuery<T>(Func<IEnumerable<T>> action)
    {
      return Task.Factory.StartNew(() => action().ToList(),
                                   CancellationToken.None,
                                   TaskCreationOptions.None,
                                   OrderedTaskScheduler.Instance);
    }
  }
}